package com.winchain.chainbill.tbill.biz.rx;

import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.basic.charge.service.ValComService;
import com.winchain.chainbill.basic.charge.service.ValRetBizService;
import com.winchain.chainbill.basic.charge.vo.ValComVo;
import com.winchain.chainbill.tbill.base.po.TbDct;
import com.winchain.chainbill.tbill.base.po.TbRec;
import com.winchain.chainbill.tbill.biz.TBill;
import com.winchain.chainbill.tbill.biz.TBillEvent;
import java.math.BigDecimal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TBillDctSaveSerFeeSubscriber extends OnErrorNotImplementedSubscriber<TBillEvent<TbDct>> {
	@Autowired
	private ValComService valComService;
	@Autowired
	private ValRetBizService valRetBizService;

	public void onApplicationEvent(TBillEvent<TbDct> t) {
		TbDct dct = (TbDct) t.getBill().getSource();
		String finId = dct.getFinId();
		String grpId = t.getBill().getRec().getGrpId();
		ValComVo valCom = this.valComService.getTbValComVo(finId, grpId);
		if (valCom != null) {
			BigDecimal valAmt = dct.getSerFee();
			String dctDate = dct.getDctDate();
			String bizId = dct.getDctId();
			String bizType = "1";
			this.valRetBizService.saveServiceFee(bizId, bizType, dctDate, valAmt, valCom, "2");
		}
	}
}
